<template>
  <div class="content">
    <div id="EchartsBar" class="echartsBar" v-show="echartsBarShows"></div>
  </div>
</template>

<script>
import echarts from "echarts";

export default {
  name: "EchartsBar",
  data() {
    return {
      echartsBarShows: true,
    };
  },
  mounted() {
    this.getBar();
  },
  methods: {
    getBar() {
      var myChart = echarts.init(document.getElementById("EchartsBar"));
      let option = {
        tooltip: {
          trigger: "axis",
          formatter(params) {
            let tip = params[0].name + "<br/>";
            for (let y = 0; y < params.length; y++) {
              tip +=
                params[y].marker +
                params[y].seriesName +
                " : " +
                params[y].value +
                " mm<br/>";
            }
            return tip;
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            name: "时间",
            type: "category",
            data: ["8：00", "9：00", "10：00"],
            axisTick: {
              alignWithLabel: true,
            },
          },
        ],
        yAxis: [
          {
            name: "降雨量" + "/mm",
            type: "value",
          },
        ],
        series: [
          {
            name: "降雨量",
            type: "bar",
            barWidth: "50%",
            data: [10, 18, 14],
            itemStyle: {
              color: "#33CCFF", //设置所有柱状图颜色
            },
          },
        ],
      };
      myChart.setOption(option);
    },
  },
};
</script>

<style>
.echartsBar {
  width: 100%;
  height: 300px;
  display: inline-block !important;
}
</style>
